<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        header a{
            text-decoration: none;
            color: #6c6c6c;
        }

    </style>
</head>
<body>
<div id="app">
    <el-container>
        <el-header height="150px">
            <div style="width: 1200px;margin: 0 auto">
                <img src="imgs/logo.png" style="width: 300px;vertical-align: middle" alt="">
                <a href="/">首页</a>
                <el-divider direction="vertical"></el-divider>
                <a href="/case.html">设计案例</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">家居商城</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">我要装修</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">设计团队</a>
                <el-divider direction="vertical"></el-divider>
                <a href="evaluate.html">用户点评</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">关于我们</a>
                <el-divider direction="vertical"></el-divider>
                <a href="javascript:void (0)" @click="goOrders()">订单详情</a>
                <span class="tel">400-800-3200</span>

            </div>
            <!--导航菜单开始-->
            <div style="background-color: #82c8ec">
                <el-menu style="width: 1200px;margin: 0 auto"
                    :default-active="activeIndex"
                    class="el-menu-demo"
                    mode="horizontal"
                    @select="handleSelect"
                    background-color="#82c8ec"
                    text-color="#fff"
                    active-text-color="#fff">
                <el-menu-item v-for="c in categoryArr" :index="c.id">{{c.name}}</el-menu-item>

                    <div style="float: right;position: relative;top: 10px">
                        <el-input placeholder="请输入搜索内容" v-model="wd">
                            <el-button slot="append" icon="el-icon-search" @click="search()"></el-button>
                        </el-input>
                    </div>
            </el-menu>
            </div>
            <!--导航菜单结束-->

        </el-header>
        <el-main style="width: 1200px;margin: 0 auto">
            <el-row gutter="20">
                <el-col span="12">
                    <el-card>
                        <img :src="p.url" width="100%" alt="">
                    </el-card>
                </el-col>
                <el-col span="12">
                    <p style="font-size: 25px">{{p.title}}</p>
                    <span style="color: #666;font-size: 12px">
                        发布于:{{p.created}}</span>
                    <el-divider></el-divider>
                    <p style="font-size: 15px;color: #666">
                        销量:{{p.saleCount}} 浏览量:{{p.viewCount}}</p>
                    <p style="font-size: 25px;font-weight: bold">
                        ￥{{p.price}}
                        <span style="font-size: 15px;color: #666"></span>
                    </p>
                    <form class="form-inline product-form col-md-12" role="form">
                    <div class="col-md-12 form-space">
                        <label >数量：</label>
                        <input type="button" value="-" @click="down()">
                        <input type="text" v-model="num" placeholder="0">
                        <input type="button" value="+" @click="plus()">
                    </div>
                    <div>
                        <input type="button" value="立即购买" @click="buy()">
                    </div>
                </form>
                </el-col>
            </el-row>
        </el-main>
        <el-footer>
            <div style="height: 95px;background-image: url('imgs/wave.png')">
            </div>
            <div style="background-color: #3f3f3f;padding:30px 0;text-align: center;color: #b1b1b1">
                <p>Copyright © 北京达内金桥科技有限公司版权所有 京ICP备12003709号-3 京公网安备 11010802029572号
                </p>
                <p>达内在线WWW.TMOOC.CN 专注于IT职业技能培训</p>
                <p>666{{v.user.id}}</p>
                <p>涵盖20余门课程体系，致力于打造权威的IT职业教育学习平台</p>
            </div>
        </el-footer>
    </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
   let v = new Vue({
        el: '#app',
        data: function() {
            return {
                activeIndex:"",
                wd:"",
                categoryArr:[],
                p:{},
                orders:{
                },
                num:"",
                user:{
                    id:"",
                    username:""
                },
                o:[{productId: "",num:"",userId:""}],
            }
        },
       methods: {
           handleSelect(key,keyPath){
               console.log(key,keyPath);
               location.href="/result.html?id="+key;
           },
           search(){
               location.href="/result.html?wd="+v.wd;
           },
           plus(){
               v.num = v.num*1+1;
           },
           down(){
               v.num = v.num-1;
           },
           buy(){
               //获取商品id
               let pid = location.search.split("=")[1];
               let o = {productId:pid,num:v.num,userId:v.user.id};
               axios.post("/orders/insert",o).then(function () {
                   v.$message.success("添加成功")
                   location.href="/orderdetail.html?id="+o.userId;
               })

           },
           goOrders(){
               location.href="/orderdetail.html?id="+v.user.id;
           }
       },
       created:function () {
            axios.get("/category/select").then(function (response) {
                v.categoryArr = response.data;
            })
           //发请求通过id获取商品详情
           axios.get("/product/selectById/detail"+location.search)
                    .then(function (response) {
               v.p = response.data;
           })
           axios.get("/currentUser").then(function (response) {
               v.user = response.data;
               if (v.user==""){
                   alert("请先登录!")
                   location.href="/login.html"
               }
           })
       }
   })
</script>
</html>
